<h1>Comics for this week</h1>

<form action="index.php?reserve=true" method="post">
<table border=1>
<th>Reserve This</th>
<th>Comic</th>
<th>Price</th>

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
	die('Could not connect: ' . mysql_error());
}

$db_selected = mysql_select_db('comic_store', $con);
if (!$db_selected) {
	die ('Can\'t use root : ' . mysql_error());
}

$result = mysql_query("SELECT * FROM comics");

while ($row = mysql_fetch_assoc($result)) {
	echo "<tr>";
	echo "<td>";
	echo "<input type=checkbox name=comic[] value=".$row['id']." />";
	echo "</td>";
	echo "<td>";
	echo $row['name'];
	echo "</td>";
	echo "<td>";
	echo $row['price'];
	echo "</td>";
	echo "</tr>";
}

mysql_close($con);
//TESTING
if($_GET['reserve'] == "true"){
	//code to check arrays
	//echo $_SESSION['user_id'];
	//print_r($_POST['comic']);
	$reserve_comics=$_POST['comic'];
	//print_r($reserve_comics[0]);
	//echo count($reserve_comics);
	
	if($_POST['submit_reserve']=="Eastwood")
		$branch=3;
	else if($_POST['submit_reserve']=="Robinson's Ermita")
		$branch=2;
	else 
		$branch=1;
	
	$con = mysql_connect("localhost","root","");
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}

	$db_selected = mysql_select_db('comic_store', $con);
	
	foreach($reserve_comics as $value){
	mysql_query("INSERT INTO comic_reservations (comic_id, user_id, reservation_date, quantity_reserved,branch_id)
	VALUES ('$value', '$_SESSION[user_id]', '2011-11-11', 1, $branch)");
	}
	
	mysql_close($con);
}
?>

</table>
Which branch would you like to reserve this at?
<input type="submit" name="submit_reserve" value="Robinson's Galleria"/>
<input type="submit" name="submit_reserve" value="Robinson's Ermita"/>
<input type="submit" name="submit_reserve" value="Eastwood"/>
</form>